package org.jeecg.gen.javaToSql;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.extern.slf4j.Slf4j;

import java.util.Set;

/**
 * @ClassName: SqlGenerator
 * @Description:根据JAVA实体生成SQL建表语句工具
 * @author: zj
 * @date: 2019年10月7日 下午2:09:00
 */
@Slf4j
public class GeneratorDatatableSql {
    static String p = "C:\\Users\\Administrator\\Desktop\\gen\\sql\\";

    public static void main(String[] args) {
        String[] packages = {"common", "agent", "company", "customer", "platform"};
        for (String aPackage : packages) {

            doAllEntity("org.jeecg.modules." + aPackage + ".entity");
        }
//		Class<?> tt= Base.class;
//		String tablename = tt.getAnnotation(TableName.class).value();
//		doOne(tt, tablename, "id", p+tablename+".sql");
    }

    private static void doAllEntity(String packageName) {
        Set<Class<?>> classList = ClassUtil.getClasses(packageName);
        System.out.println(classList);
        Object[] ts = classList.toArray();
        for (Object t : ts) {
            Class<?> tt = (Class<?>) t;
            System.out.println(tt.getName());
            String tablename = tt.getAnnotation(TableName.class).value();
            String database = "xbZ";
            String path = p + database + ".sql";
            String id = "id";
            doOne(tt, tablename, id, path);
        }

    }

    private static void doOne(Class<?> tt, String tablename, String id, String path) {
        SqlGenerator.generateSql(tt.getName(),  tablename, id, path);

    }

}